/*
 * Component.h
 *
 *  Created on: May 15, 2012
 *      Author: quyetnd
 */

#ifndef __AchillesDefense__Component__
#define __AchillesDefense__Component__

#include <iostream>
#include "cocos2d.h"
#include "../Common/PlistData.h"

using namespace cocos2d;
using namespace std;

class Component : public CCSprite{
protected:
	CCDictionary<std::string, CCAction*> *stateDictionary;
	CCAction* currentAnimation;

	CCObject* objectCallFunc;
	SEL_CallFunc callbackFunc;

	CCMutableArray<CCSpriteFrame*>* createFrameArray(const char* framePrefix,const char* frameExtension,int firstFrameIndex, int lastFrameIndex);
	void loadState(PlistData* data);
	void loadStateWithKey(PlistData* data,const char* key);
public:
	Component();
	Component(const char* plistFile,bool loadFrame = false);
	virtual ~Component();
	
    static Component* createSprite();
	static Component* componentWithFile(const char *file, bool loadFrames);
    
    void registerAnimation(const char* state, const char* framePrefix,const char* frameExtension,int firstFrameIndex, int lastFrameIndex, float frameDuration, bool forever,bool reverse);
	void registerSprite(const char* sprite,const char* fileName);
    
	bool setAnimation(const char* state, CCObject* target, SEL_CallFunc callback, bool isLog = false);
	bool setAnimation(const char* state);
    
    void removeFromParentWithCleanup();
    void removeFromParentWithoutCleanup();
};


#endif /* defined(__AchillesDefense__Component__) */
